package com.sun.util.limit;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.jdbc.core.JdbcTemplate;

import com.sun.app.service.BaseService;




public class CompareUtil{
	
	public static String COMPARE_MSGBOARD_LIMITS="select MSGBOARD from c_limits where UID=?";
	public static String COMPARE_BASEINFO_LIMITS="select INFO from c_limits where UID=?";
	public static String COMPARE_MYSTATUS_LIMITS="select MYSTATUS from c_limits where UID=?";
	public static String COMPARE_SCHOOLINFO_LIMITS="select SCHOOLINFO from c_limits where UID=?";
	public static String COMPARE_MYTIPS_LIMITS="select MYTIPS from c_limits where UID=?";
	public static String COMPARE_MYNEWS_LIMITS="select MYNEWS from c_limits where UID=?";
	public static String COMPARE_MYROUND_LIMITS="select MYROUND from c_limits where UID=?";
	public static String COMPARE_MYACTIVITY_LIMITS="select MYACTIVITY from c_limits where UID=?";
	
	public static String SELECT_CITY_SCHOOL="select CITY,SCHOOL from c_user where UID=?";
	public static String SELECT_MYFRIEND="select STATE from c_friend where UID=? and FRIENDID=?";
	
	
	public static boolean compare(JdbcTemplate jt,String fUid, String tUid, String type) {
		// TODO Auto-generated method stub
//		String limitStr = "";
//		for(LimitType l : LimitType.values()){
//			if(l.toString()==type || l.toString().equals(type)){
//				limitStr=l.toString();
//			}
//		}
		int limits = 0;
		System.out.println("fUid=============>"+fUid+"tUid============>"+tUid);
		if(type=="COMPARE_MSGBOARD_LIMITS" || type.equals("COMPARE_MSGBOARD_LIMITS")){
			limits = jt.queryForInt(COMPARE_MSGBOARD_LIMITS,tUid);
		}else if(type=="COMPARE_BASEINFO_LIMITS" || type.equals("COMPARE_BASEINFO_LIMITS")){
			limits = jt.queryForInt(COMPARE_BASEINFO_LIMITS,tUid);
		}else if(type=="COMPARE_MYSTATUS_LIMITS" || type.equals("COMPARE_MYSTATUS_LIMITS")){
			limits = jt.queryForInt(COMPARE_MYSTATUS_LIMITS,tUid);
		}else if(type=="COMPARE_SCHOOLINFO_LIMITS" || type.equals("COMPARE_SCHOOLINFO_LIMITS")){
			limits = jt.queryForInt(COMPARE_SCHOOLINFO_LIMITS,tUid);
		}else if(type=="COMPARE_MYTIPS_LIMITS" || type.equals("COMPARE_MYTIPS_LIMITS")){
			limits = jt.queryForInt(COMPARE_MYTIPS_LIMITS,tUid);
		}else if(type=="COMPARE_MYNEWS_LIMITS" || type.equals("COMPARE_MYNEWS_LIMITS")){
			limits = jt.queryForInt(COMPARE_MYNEWS_LIMITS,tUid);
		}else if(type=="COMPARE_MYROUND_LIMITS" || type.equals("COMPARE_MYROUND_LIMITS")){
			System.out.println("123");
			limits = jt.queryForInt(COMPARE_MYROUND_LIMITS,tUid);
			System.out.println("321");
		}else if(type=="COMPARE_MYACTIVITY_LIMITS" || type.equals("COMPARE_MYACTIVITY_LIMITS")){
			limits = jt.queryForInt(COMPARE_MYACTIVITY_LIMITS,tUid);
		}
		if(fUid==null){
			if(limits==0){
				return true;
			}
			else{
				return false;
			}
		}
		
		int iTofStatus = jt.queryForInt(SELECT_MYFRIEND,fUid,tUid);
		int fToiStatus = jt.queryForInt(SELECT_MYFRIEND,tUid,fUid);
		
		Map<String, Object> iTofCSStatus = jt.queryForMap(SELECT_CITY_SCHOOL,fUid);
		String iTofCity = (String) iTofCSStatus.get("CITY");
		String iTofSchool= (String) iTofCSStatus.get("SCHOOL");
		Map<String, Object> fToiCSStatus = jt.queryForMap(SELECT_CITY_SCHOOL,fUid);
		String fToiCity = (String) fToiCSStatus.get("CITY");
		String fToiSchool = (String) fToiCSStatus.get("SCHOOL");
		if(iTofStatus==1&&iTofStatus==fToiStatus){
			//好友
			if(limits<3)
				return true;
			else
				return false;
		}
		else if(iTofCity==fToiCity || iTofCity.equals(fToiCity)){
			//同城
			if(limits<2){
				return true;
			}
			return false;
		}else if(iTofSchool==fToiSchool || iTofSchool.equals(fToiSchool)){
			//同学校
			if(limits<2){
				return true;
			}
			return false;
		}else{
			return false;
		}
	}


}
